/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package freewolf;

import com.puzzud.engine.core.Entity;

/**
 *
 * @author puzzud
 */
public class Room extends Entity
{
    protected Room adjacentRoom[];

    public static int NORTH      = 0;
    public static int EAST       = 1;
    public static int WEST       = 2;
    public static int SOUTH      = 3;

    public static int WIDTH      = 33;
    public static int HEIGHT     = 19;

    public Room()
    {
        adjacentRoom = new Room[4];

        int index;
        for( index = 0; index < adjacentRoom.length; index++ )
        {
            adjacentRoom[index] = null;
        }
    }

    public int getHeight()
    {
        return( HEIGHT );
    }

    public void setHeight( int height )
    {
        //this.height = height;
    }

    public int getWidth()
    {
        return( WIDTH );
    }

    public void setWidth( int width )
    {
        //this.width = width;
    }

    public void attachRoom( Room room, int wall )
    {
        if( room == null )
        {
            return;
        }
        else
        {
            Room oldRoom = adjacentRoom[wall];
            adjacentRoom[wall] = room;

            int oppositeWall = SOUTH - wall;
            if( room.getAdjacentRoom( oppositeWall ) != this  )
            {
                room.attachRoom( this, oppositeWall );
            }

            if( oldRoom != null )
            {
                if( oldRoom.getAdjacentRoom( oppositeWall ) == this )
                {
                    oldRoom.detachRoom( oppositeWall );
                }
            }
        }
    }

    public Room detachRoom( int wall )
    {
        Room oldRoom = adjacentRoom[wall];
        adjacentRoom[wall] = null;

        int oppositeWall = SOUTH - wall;
        if( oldRoom.getAdjacentRoom( oppositeWall ) == this )
        {
            oldRoom.detachRoom( oppositeWall );
        }

        return( oldRoom );
    }

    public Room getAdjacentRoom( int wall )
    {
        return( adjacentRoom[wall] );
    }
}
